//
//  NMPOHomeCell.swift
//  NMPO
//
//  Created by PowerfullClean on 2023/10/31.
//

import UIKit
import Lottie

class NMPOHomCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.addSubview(nmpo_titleLabel)
        contentView.addSubview(nmpo_bottomView)
        contentView.addSubview(nmpo_connectButton)
        contentView.addSubview(nmpo_downloadLabel)
        contentView.addSubview(nmpo_downloadValueLabel)
        contentView.addSubview(nmpo_downUnitLabel)
        contentView.addSubview(nmpo_uploadLabel)
        contentView.addSubview(nmpo_uploadValueLabel)
        contentView.addSubview(nmpo_upUnitLabel)
        contentView.addSubview(nmpo_changeView)
        contentView.addSubview(nmpo_selectView)
        contentView.addSubview(nmpo_ipView)
        contentView.addSubview(nmpo_speedView)
        contentView.addSubview(nmpo_connectAnimeView)
        contentView.addSubview(nmpo_disConnectAnimeView)
        contentView.addSubview(nmpo_iPValueLabel)
        contentView.addSubview(nmpo_timeView)
        nmpo_ipView.snp.makeConstraints { make in
            make.size.equalTo(102)
            make.right.equalToSuperview().offset(-20)
            make.centerY.equalTo(nmpo_titleLabel.snp.centerY)
        }
        nmpo_speedView.snp.makeConstraints { make in
            make.size.equalTo(102)
            make.right.equalTo(nmpo_ipView.snp.left).offset(2)
            make.top.equalTo(nmpo_titleLabel.snp.bottom).offset(5)
        }
        nmpo_titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(44)
            make.left.equalToSuperview().offset(20)
            make.height.equalTo(35)
        }
        nmpo_bottomView.snp.makeConstraints { make in
            make.height.equalTo(510)
            make.left.equalToSuperview()
            make.bottom.equalToSuperview().offset(20)
            make.right.equalToSuperview()
        }
        nmpo_connectButton.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 190, height: 200))
            make.right.equalToSuperview()
            make.top.equalTo(nmpo_bottomView.snp.top)
        }
        nmpo_downloadLabel.snp.makeConstraints { make in
            make.top.equalTo(nmpo_bottomView.snp.top).offset(20)
            make.left.equalToSuperview().offset(28)
        }
        nmpo_downloadValueLabel.snp.makeConstraints { make in
            make.top.equalTo(nmpo_downloadLabel.snp.bottom)
            make.centerX.equalTo(nmpo_downloadLabel.snp.centerX)
            make.height.equalTo(28)
        }
        nmpo_downUnitLabel.snp.makeConstraints { make in
            make.top.equalTo(nmpo_downloadValueLabel.snp.bottom)
            make.centerX.equalTo(nmpo_downloadLabel.snp.centerX)
        }
        nmpo_uploadLabel.snp.makeConstraints { make in
            make.top.equalTo(nmpo_downUnitLabel.snp.bottom).offset(16)
            make.centerX.equalTo(nmpo_downloadLabel.snp.centerX)
        }
        nmpo_uploadValueLabel.snp.makeConstraints { make in
            make.top.equalTo(nmpo_uploadLabel.snp.bottom)
            make.centerX.equalTo(nmpo_uploadLabel.snp.centerX)
            make.height.equalTo(28)
        }
        nmpo_upUnitLabel.snp.makeConstraints { make in
            make.top.equalTo(nmpo_uploadValueLabel.snp.bottom)
            make.centerX.equalTo(nmpo_uploadLabel.snp.centerX)
        }
        nmpo_changeView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(72)
            make.top.equalTo(nmpo_connectButton.snp.bottom).offset(8)
        }
        nmpo_selectView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(68)
            make.top.equalTo(nmpo_changeView.snp.bottom).offset(6)
        }
        nmpo_connectAnimeView.snp.makeConstraints { make in
            make.edges.equalTo(nmpo_connectButton)
        }
        nmpo_disConnectAnimeView.snp.makeConstraints { make in
            make.edges.equalTo(nmpo_connectButton)
        }
        
        nmpo_iPValueLabel.snp.makeConstraints { make in
            make.left.equalTo(nmpo_titleLabel.snp.left)
            make.top.equalTo(nmpo_titleLabel.snp.bottom).offset(10)
        }
        nmpo_timeView.snp.makeConstraints { make in
            make.top.left.equalTo(nmpo_bottomView)
            make.right.equalTo(nmpo_connectButton.snp.left).offset(-5)
            make.bottom.equalTo(nmpo_uploadValueLabel.snp.bottom)
        }
        contentView.layer.masksToBounds = true
        
        NMPOManager.nmpo_manager.nmpo_vpnChangeBlock = {[weak self] nmpo_state in
            //            print(nmpo_state.nmpo_title)
            
            if nmpo_state == .nmpo_connected {
                self?.nmpo_connectButton.isSelected = true
                self?.nmpo_connectAnimeView.isHidden = true
                self?.nmpo_connectAnimeView.stop()
                self?.nmpo_disConnectAnimeView.isHidden = true
                self?.nmpo_disConnectAnimeView.stop()
                //                self?.nmpo_ipView.isHidden = false
                //                self?.nmpo_speedView.isHidden = false
                self?.nmpo_titleLabel.text = "CONNECTED"
                self?.nmpo_viewGetVController?.navigationController?.pushViewController(NMPOVpnResultViewController(nmpo_connected: true), animated: true)
                
            }
            if nmpo_state == .nmpo_connecting {
                
                self?.nmpo_titleLabel.text = "CONNECTING"
                if !(self?.nmpo_connectAnimeView.isAnimationPlaying ?? false) {
                    self?.nmpo_connectAnimeView.isHidden = false
                    self?.nmpo_connectAnimeView.play()
                }
            }
            if nmpo_state == .nmpo_disconnecting {
                self?.nmpo_titleLabel.text = "DISCONNECTING"
                if !(self?.nmpo_disConnectAnimeView.isAnimationPlaying ?? false) {
                    self?.nmpo_disConnectAnimeView.isHidden = false
                    self?.nmpo_disConnectAnimeView.play()
                }
            }
            if nmpo_state == .nmpo_disconnected {
                self?.nmpo_connectButton.isSelected = false
                self?.nmpo_disConnectAnimeView.isHidden = true
                self?.nmpo_disConnectAnimeView.stop()
                self?.nmpo_connectAnimeView.isHidden = true
                self?.nmpo_connectAnimeView.stop()
                //                self?.nmpo_ipView.isHidden = true
                //                self?.nmpo_speedView.isHidden = true
                self?.nmpo_titleLabel.text = "NO CONNECT"
                self?.nmpo_viewGetVController?.navigationController?.pushViewController(NMPOVpnResultViewController(nmpo_connected: false), animated: true)
                
            }
            if nmpo_state == .nmpo_invalid {
                self?.nmpo_connectButton.isSelected = false
                self?.nmpo_disConnectAnimeView.isHidden = true
                self?.nmpo_disConnectAnimeView.stop()
                self?.nmpo_connectAnimeView.isHidden = true
                self?.nmpo_connectAnimeView.stop()
                //                self?.nmpo_ipView.isHidden = true
                //                self?.nmpo_speedView.isHidden = true
                self?.nmpo_titleLabel.text = "NO CONNECT"
                
                
            }
        }
        NMPOManager.nmpo_manager.nmpo_vpnAuthAction {[weak self] _, _ in
            if NMPOManager.nmpo_manager.nmpo_vpnCurStateType == .nmpo_connected {
                self?.nmpo_connectButton.isSelected = true
                self?.nmpo_ipView.isHidden = false
                self?.nmpo_speedView.isHidden = false
                self?.nmpo_titleLabel.text = "CONNECTED"
            }
        }
       
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK: - nmpo action
    func nmpo_addAnmate() {
        nmpo_connectButton.layer.removeAllAnimations()
        if NMPOManager.nmpo_manager.nmpo_vpnCurStateType == .nmpo_invalid ||  NMPOManager.nmpo_manager.nmpo_vpnCurStateType == .nmpo_disconnected  {
            nmpo_connectButton.layer.add(nmpo_loadingKey, forKey: "nmpo_loadingKey")
        }
        
    }
    func nmpo_reloadIpShow() {
        if NMPOManager.nmpo_manager.nmpo_vpnCurStateType == .nmpo_connected {
            nmpo_iPValueLabel.text = NMPOManager.nmpo_manager.nmpo_curServerModel?.nmpo_address
            nmpo_timeView.isHidden = true
            nmpo_downloadLabel.isHidden = false
            nmpo_downloadValueLabel.isHidden = false
            nmpo_uploadLabel.isHidden = false
            nmpo_uploadValueLabel.isHidden = false
            nmpo_downUnitLabel.isHidden = false
            nmpo_upUnitLabel.isHidden = false
        }else {
            nmpo_iPValueLabel.text = ""
            nmpo_timeView.isHidden = false
            nmpo_downloadLabel.isHidden = true
            nmpo_downloadValueLabel.isHidden = true
            nmpo_uploadLabel.isHidden = true
            nmpo_uploadValueLabel.isHidden = true
            nmpo_downUnitLabel.isHidden = true
            nmpo_upUnitLabel.isHidden = true
        }
        nmpo_addAnmate()
    }
    @objc func nmpo_connectClick() {
        NMPOManager.nmpo_manager.nmpo_smart = false
        NMPOManager.nmpo_manager.nmpo_best = false
        if NMPOManager.nmpo_manager.nmpo_vpnCurStateType == .nmpo_connected {
            NMPOManager.nmpo_manager.nmpo_stopConnect()
            NMPOManager.nmpo_manager.nmpo_vpnStateClickType = .nmpo_disConnect
            
        }else {
            NMPOManager.nmpo_manager.nmpo_vpnStateClickType = .nmpo_connect
            NMPOManager.nmpo_manager.nmpo_connectSelectAddreddAction()
        }
    }
    @objc func nmpo_changeServersClick() {
        nmpo_viewGetVController?.navigationController?.pushViewController(NMPOSersListViewController(), animated: true)
    }
    @objc func nmpo_testClick(nmpo_view: UITapGestureRecognizer) {
        if NMPOManager.nmpo_manager.nmpo_netType == .nmpo_none {
            NMPOHudVender.nmpo_showMessage("No available network", isError: false)
            return
        }
        if nmpo_view.view == nmpo_ipView {
            nmpo_viewGetVController?.navigationController?.pushViewController(NMPOScanViewController(nmpo_funcType: .nmpo_ip), animated: true)
            return
        }
        if nmpo_view.view == nmpo_speedView {
            nmpo_viewGetVController?.navigationController?.pushViewController(NMPOScanViewController(nmpo_funcType: .nmpo_speed), animated: true)
        }
    }
    func nmpo_reloadSpeedValue() {
        if NMPOManager.nmpo_manager.nmpo_vpnCurStateType == .nmpo_connected {
            let nmpo_down = NMPOCommon.nmpo_getSizeValue(size: NMPOManager.nmpo_manager.nmpo_homeDownloadValue)
            let nmpo_up = NMPOCommon.nmpo_getSizeValue(size: NMPOManager.nmpo_manager.nmpo_homeUploadValue)
            nmpo_downloadValueLabel.text = nmpo_down.0
            nmpo_upUnitLabel.text = nmpo_down.1
            nmpo_uploadValueLabel.text = nmpo_up.0
            nmpo_downUnitLabel.text = nmpo_up.1
        }else {
            nmpo_downloadValueLabel.text = "-"
            nmpo_uploadValueLabel.text = "-"
            nmpo_upUnitLabel.text = "MB/s"
            nmpo_downUnitLabel.text = "MB/s"
        }
    }
    //MARK: - nmpo lazy
    lazy var nmpo_loadingKey: CABasicAnimation = {
        let nmpo_loadingKey = CABasicAnimation.init(keyPath: "transform.scale")
        nmpo_loadingKey.fromValue = 1.0 // 初始缩放比例
        nmpo_loadingKey.toValue = 1.1   // 最终缩放比例
        nmpo_loadingKey.duration = 0.5   // 动画持续时间（秒）
        nmpo_loadingKey.autoreverses = true // 自动返回到初始状态
        nmpo_loadingKey.repeatCount = MAXFLOAT
        return nmpo_loadingKey
    }()
    lazy var nmpo_iPValueLabel: UILabel = {
        let nmpo_valueLabel = UILabel()
        nmpo_valueLabel.font = UIFont.systemFont(ofSize: 12)
        nmpo_valueLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF, a: 0.45)
        nmpo_valueLabel.text = ""
        return nmpo_valueLabel
    }()
    lazy var nmpo_ipView: NMPOHomeTestItemView = {
        let nmpo_ipView = NMPOHomeTestItemView()
//        nmpo_ipView.isHidden = true
        nmpo_ipView.nmpo_addTap(target: self,action: #selector(nmpo_testClick(nmpo_view:)))
        return nmpo_ipView
    }()
    lazy var nmpo_speedView: NMPOHomeTestItemView = {
        let nmpo_speedView = NMPOHomeTestItemView()
        nmpo_speedView.nmpo_iconView.image = UIImage(named: "nmpo_home_speed")
        nmpo_speedView.nmpo_titleLabel.text = "NET test"
//        nmpo_speedView.isHidden = true
        nmpo_speedView.nmpo_addTap(target: self,action: #selector(nmpo_testClick(nmpo_view:)))
        return nmpo_speedView
    }()
    lazy var nmpo_bottomView: UIImageView = {
        let nmpo_bottomView = UIImageView(image: UIImage(named: "nmpo_home_connectbg"))
        return nmpo_bottomView
    }()
    lazy var nmpo_connectButton: UIButton = {
        let nmpo_connectButton = UIButton()
        nmpo_connectButton.setBackgroundImage(UIImage(named: "nmpo_home_connect"), for: .normal)
        nmpo_connectButton.setBackgroundImage(UIImage(named: "nmpo_home_disConnect"), for: .selected)
        nmpo_connectButton.addTarget(self, action: #selector(nmpo_connectClick), for: .touchUpInside)
        return nmpo_connectButton
    }()
    lazy var nmpo_connectAnimeView: LottieAnimationView = {
        let nmpo_connectAnimeView = LottieAnimationView(name: "nmpo_startAnmate")
        nmpo_connectAnimeView.loopMode = .loop
        nmpo_connectAnimeView.backgroundBehavior = .pauseAndRestore
        nmpo_connectAnimeView.animationSpeed = 1
        nmpo_connectAnimeView.contentMode = .scaleAspectFit
//        nmpo_connectAnimeView.play()
        nmpo_connectAnimeView.isHidden = true
        return nmpo_connectAnimeView
    }()
    lazy var nmpo_disConnectAnimeView: LottieAnimationView = {
        let nmpo_disConnectAnimeView = LottieAnimationView(name: "nmpo_stopAnmate")
        nmpo_disConnectAnimeView.loopMode = .loop
        nmpo_disConnectAnimeView.backgroundBehavior = .pauseAndRestore
        nmpo_disConnectAnimeView.animationSpeed = 1
        nmpo_disConnectAnimeView.contentMode = .scaleAspectFit
//        nmpo_disConnectAnimeView.play()
        nmpo_disConnectAnimeView.isHidden = true
        return nmpo_disConnectAnimeView
    }()
    lazy var nmpo_titleLabel: UILabel = {
        let nmpo_titleLabel = UILabel()
        nmpo_titleLabel.font = UIFont.systemFont(ofSize: 24)
        nmpo_titleLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF)
        nmpo_titleLabel.text = "NO CONNECT"
        return nmpo_titleLabel
    }()
    lazy var nmpo_downloadLabel: UILabel = {
        let nmpo_downloadLabel = UILabel()
        nmpo_downloadLabel.font = UIFont.systemFont(ofSize: 14)
        nmpo_downloadLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF, a: 0.45)
        nmpo_downloadLabel.text = "DOWNLOAD"
        return nmpo_downloadLabel
    }()
    lazy var nmpo_downloadValueLabel: UILabel = {
        let nmpo_valueLabel = UILabel()
        nmpo_valueLabel.font = UIFont.systemFont(ofSize: 20)
        nmpo_valueLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF)
        nmpo_valueLabel.text = "-"
        return nmpo_valueLabel
    }()
    lazy var nmpo_downUnitLabel: UILabel = {
        let nmpo_downUnitLabel = UILabel()
        nmpo_downUnitLabel.font = UIFont.systemFont(ofSize: 12)
        nmpo_downUnitLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF, a: 0.22)
        nmpo_downUnitLabel.text = "MB/s"
        return nmpo_downUnitLabel
    }()
    lazy var nmpo_uploadLabel: UILabel = {
        let nmpo_uploadLabel = UILabel()
        nmpo_uploadLabel.font = UIFont.systemFont(ofSize: 14)
        nmpo_uploadLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF, a: 0.45)
        nmpo_uploadLabel.text = "UPLOAD"
        return nmpo_uploadLabel
    }()
    lazy var nmpo_uploadValueLabel: UILabel = {
        let nmpo_uploadValueLabel = UILabel()
        nmpo_uploadValueLabel.font = UIFont.systemFont(ofSize: 20)
        nmpo_uploadValueLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF)
        nmpo_uploadValueLabel.text = "-"
        return nmpo_uploadValueLabel
    }()
    lazy var nmpo_upUnitLabel: UILabel = {
        let nmpo_upUnitLabel = UILabel()
        nmpo_upUnitLabel.font = UIFont.systemFont(ofSize: 12)
        nmpo_upUnitLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF, a: 0.22)
        nmpo_upUnitLabel.text = "MB/s"
        return nmpo_upUnitLabel
    }()
    lazy var nmpo_changeView: NMPOHomeChangeServerView = {
        let nmpo_changeView = NMPOHomeChangeServerView()
        nmpo_changeView.nmpo_addTap(target: self, action: #selector(nmpo_changeServersClick))
        return nmpo_changeView
    }()
    lazy var nmpo_selectView: NMPOHomeSelectView = {
        let nmpo_selectView = NMPOHomeSelectView()
        nmpo_selectView.nmpo_homeSelectBock = {[weak self] in
            self?.nmpo_connectAnimeView.isHidden = false
            self?.nmpo_connectAnimeView.play()
            NMPOManager.nmpo_manager.nmpo_vpnStateClickType = .nmpo_disConnect
            NMPOManager.nmpo_manager.nmpo_connectSmartAction()
        }
        return nmpo_selectView
    }()
    lazy var nmpo_timeView: NMPOHomeTimeView = {
        let nmpo_timeView = NMPOHomeTimeView()
        return nmpo_timeView
    }()
}

class NMPOHomeChangeServerView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(nmpo_bottomView)
        addSubview(nmpo_iconView)
        addSubview(nmpo_titleLabel)
        addSubview(nmpo_arrowView)
        nmpo_bottomView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        nmpo_iconView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(18)
            make.left.equalToSuperview().offset(20)
            make.size.equalTo(CGSize(width: 56, height: 32))
        }
        nmpo_titleLabel.snp.makeConstraints { make in
            make.centerY.equalTo(nmpo_iconView.snp.centerY)
            make.left.equalTo(nmpo_iconView.snp.right).offset(12)
        }
        nmpo_arrowView.snp.makeConstraints { make in
            make.size.equalTo(18)
            make.centerY.equalTo(nmpo_iconView.snp.centerY)
            make.right.equalToSuperview().offset(-24)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var nmpo_bottomView: UIImageView = {
        let nmpo_bottomView = UIImageView(image: UIImage(named: "nmpo_home_change"))
        return nmpo_bottomView
    }()
    lazy var nmpo_iconView: UIImageView = {
        let nmpo_iconView = UIImageView(image: UIImage(named: "nmpo_home_changeIcon"))
        return nmpo_iconView
    }()
    lazy var nmpo_titleLabel: UILabel = {
        let nmpo_titleLabel = UILabel()
        nmpo_titleLabel.font = UIFont.systemFont(ofSize: 12)
        nmpo_titleLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF)
        nmpo_titleLabel.text = "Change severs"
        return nmpo_titleLabel
    }()
    lazy var nmpo_arrowView: UIImageView = {
        let nmpo_arrowView = UIImageView(image: UIImage(named: "nmpo_home_changeArrow"))
        return nmpo_arrowView
    }()
}

class NMPOHomeSelectView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(nmpo_bottomView)
        addSubview(nmpo_bestView)
        addSubview(nmpo_smartView)
        nmpo_bottomView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        nmpo_bestView.snp.makeConstraints { make in
            make.left.bottom.height.equalToSuperview()
            make.right.equalTo(self.snp.centerX)
        }
        nmpo_smartView.snp.makeConstraints { make in
            make.right.bottom.height.equalToSuperview()
            make.left.equalTo(self.snp.centerX)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    @objc func nmpo_serverConnectClick(nmpo_tap: UITapGestureRecognizer) {
        if nmpo_tap.view == nmpo_bestView {
            NMPOManager.nmpo_manager.nmpo_smart = false
            NMPOManager.nmpo_manager.nmpo_best = true
            
        }else
        if nmpo_tap.view == nmpo_smartView {
            NMPOManager.nmpo_manager.nmpo_best = false
            NMPOManager.nmpo_manager.nmpo_smart = true
        }
        nmpo_homeSelectBock?()
    }
    var nmpo_homeSelectBock:(()->())?
    lazy var nmpo_bottomView: UIImageView = {
        let nmpo_bottomView = UIImageView(image: UIImage(named: "nmpo_home_selectbg"))
        return nmpo_bottomView
    }()
    lazy var nmpo_bestView: NMPOHomeSelectItemView = {
        let nmpo_bestView = NMPOHomeSelectItemView()
        nmpo_bestView.nmpo_addTap(target: self, action: #selector(nmpo_serverConnectClick(nmpo_tap:)))
        return nmpo_bestView
    }()
    lazy var nmpo_smartView: NMPOHomeSelectItemView = {
        let nmpo_smartView = NMPOHomeSelectItemView()
        nmpo_smartView.nmpo_titleLabel.text = "Stable servers"
        nmpo_smartView.nmpo_addTap(target: self, action: #selector(nmpo_serverConnectClick(nmpo_tap:)))
        return nmpo_smartView
    }()
}

class NMPOHomeSelectItemView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(nmpo_titleLabel)
        addSubview(nmpo_arrowView)
        nmpo_titleLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(16)
        }
        nmpo_arrowView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-10)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var nmpo_titleLabel: UILabel = {
        let nmpo_titleLabel = UILabel()
        nmpo_titleLabel.font = UIFont.systemFont(ofSize: 12)
        nmpo_titleLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF)
        nmpo_titleLabel.text = "Best severs"
        return nmpo_titleLabel
    }()
    lazy var nmpo_arrowView: UIImageView = {
        let nmpo_arrowView = UIImageView(image: UIImage(named: "nmpo_home_selectArrow"))
        return nmpo_arrowView
    }()
}

class NMPOHomeTestItemView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(nmpo_bgView)
        addSubview(nmpo_titleLabel)
        addSubview(nmpo_iconView)
        nmpo_bgView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        nmpo_titleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(nmpo_iconView.snp.bottom).offset(4)
        }
        nmpo_iconView.snp.makeConstraints { make in
            make.size.equalTo(24)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(30)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var nmpo_bgView: UIImageView = {
        let nmpo_bgView = UIImageView(image: UIImage(named: "nmpo_home_testBg"))
        return nmpo_bgView
    }()
    lazy var nmpo_titleLabel: UILabel = {
        let nmpo_titleLabel = UILabel()
        nmpo_titleLabel.font = UIFont.systemFont(ofSize: 12)
        nmpo_titleLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF)
        nmpo_titleLabel.text = "IP info"
        return nmpo_titleLabel
    }()
    lazy var nmpo_iconView: UIImageView = {
        let nmpo_iconView = UIImageView(image: UIImage(named: "nmpo_home_ip"))
        return nmpo_iconView
    }()
}


class NMPOHomeTimeView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(nmpo_titleLabel)
        addSubview(nmpo_timeLabel)
        nmpo_titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(55)
            make.centerX.equalToSuperview()
        }
        nmpo_timeLabel.snp.makeConstraints { make in
            make.top.equalTo(nmpo_titleLabel.snp.bottom).offset(16)
            make.centerX.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var nmpo_titleLabel: UILabel = {
        let nmpo_titleLabel = UILabel()
        nmpo_titleLabel.font = UIFont.systemFont(ofSize: 14)
        nmpo_titleLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF, a: 0.45)
        nmpo_titleLabel.text = "TO CONNECT"
        return nmpo_titleLabel
    }()
    lazy var nmpo_timeLabel: UILabel = {
        let nmpo_timeLabel = UILabel()
        nmpo_timeLabel.font = UIFont.systemFont(ofSize: 24)
        nmpo_timeLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF)
        nmpo_timeLabel.text = "00:00:00"
        return nmpo_timeLabel
    }()
}
